package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.FastPublishProductSeatCheckBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.FastPublishProductSeatCheckCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;
/**
*快速发布商品坑位检测
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_FastPublishProductSeatCheck{
	private static FastPublishProductSeatCheckBean fastpublishproductseatcheckBean;
	private static FastPublishProductSeatCheckCall fastpublishproductseatcheckCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("快速发布商品坑位检测");
	}

	@Before
	public void caseUp() {
		fastpublishproductseatcheckBean=new FastPublishProductSeatCheckBean();
		fastpublishproductseatcheckCall=new FastPublishProductSeatCheckCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(fastpublishproductseatcheckCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_FastPublishProductSeatCheck_01() {
		Logger.start(true,"快速发布商品坑位检测,true");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.UpdateLiveTimeToStart(createlive.getId());
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			fastpublishproductseatcheckBean.setSellerId(sellerId);
			fastpublishproductseatcheckBean.setLiveId(createlive.getId());
			fastpublishproductseatcheckCall.setData(fastpublishproductseatcheckBean);
			fastpublishproductseatcheckCall.callService();			
			Logger.verifyEquals("200",fastpublishproductseatcheckCall.getString("Code"),"验证code");
			Logger.verifyEquals(true,fastpublishproductseatcheckCall.getJsonObject().get("Data").getAsJsonObject().get("CheckResult").getAsBoolean(),"验证CheckResult");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore //耗时太长
	public void Tc_FastPublishProductSeatCheck_02() throws Exception {
		Logger.start(true,"快速发布商品坑位检测,false");
		try{
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.UpdateLiveTimeToStart(createlive.getId());
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			for (int i=0;i<81;i++){
				AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
				addProdReq.getProduct().setLiveRoomId(createlive.getId());
				ProductManagerCallServiceV2.addNewProduct(addProdReq);
			}
			fastpublishproductseatcheckBean.setSellerId(sellerId);
			fastpublishproductseatcheckBean.setLiveId(createlive.getId());
			fastpublishproductseatcheckCall.setData(fastpublishproductseatcheckBean);
			fastpublishproductseatcheckCall.callService();
			Logger.verifyEquals(false,fastpublishproductseatcheckCall.getJsonObject().get("Data").getAsJsonObject().get("CheckResult").getAsBoolean(),"验证CheckResult");
			Logger.verifyEquals("快速发布已达上限",fastpublishproductseatcheckCall.getJsonObject().get("Data").getAsJsonObject().get("CheckMsg").getAsBoolean(),"验证CheckResult");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
}